Skip to content

Added new properties to easily check the node type#186

Merged
rushter merged 7 commits intorushter:masterfrom
pygarap:skip_empty
Nov 19, 2025
Merged

Added new properties to easily check the node type#186
rushter merged 7 commits intorushter:masterfrom
pygarap:skip_empty

Conversation

@pygarap
Copy link
Contributor

@pygarap pygarap commented Nov 16, 2025

Note

Added multiple new properties to LexborNode for better node type checks (is_element_node, is_text_node, is_comment_node, is_document_node).

This pull request introduces a series of enhancements and additions to the selectolax library, focusing on expanding the public API for both LexborNode and LexborHTMLParser, improving type hinting, and refining the development workflow. The changes include new properties and methods for node type checking, traversal, manipulation, and attribute access, as well as improvements to the linting process.

API Enhancements for Node and Parser Classes:

  • Added multiple new properties and methods to LexborNode in selectolax/lexbor.pyi for better node inspection, traversal, and manipulation, including node type checks (is_element_node, is_text_node, etc.), new traversal methods (traverse, iter), and manipulation methods (unwrap, unwrap_tags, merge_text_nodes, replace_with, insert_before, insert_after, insert_child, decompose, remove, strip_tags). Also added new attribute accessors (attributes, attrs, id, raw_value, text_content) and selector utilities (css, css_first, any_css_matches, css_matches, select). [1] [2] [3] [4] [5] [6] [7] [8] [9] [10] [11] [12] [13] [14] [15] [16] [17] [18] [19] [20] [21] [22] [23] [24] [25] [26] [27] [28]
  • Added new methods and properties to LexborHTMLParser in selectolax/lexbor.pyi, such as body, head, tags, text, html, css, and multiple overloads for css_first, improving the ability to query and interact with the parsed document. [1] [2] [3] [4] [5] [6]

Type Hinting and Internal API Improvements:

  • Declared a new internal method _is_node_type in LexborNode in selectolax/lexbor.pxd to support node type checking logic.

Developer Workflow Improvements:

  • Updated the Makefile to improve linting: now runs ruff format and ruff check --fix to automatically format and fix style issues in selectolax and tests, in addition to running mypy.

Type Stubs and Documentation:

  • Added and documented new methods in the type stub files (selectolax/lexbor.pyi) for both LexborNode and LexborSelector, ensuring that type hints and docstrings are up-to-date and comprehensive for all new and existing methods. [1] [2]

These changes significantly enhance the usability and introspection capabilities of the library, making it easier for developers to work with HTML nodes and documents programmatically.

…_node` with `_is_node_type` helper methods for consistency
@pygarap pygarap requested a review from rushter November 18, 2025 22:45
@pygarap
Copy link
Contributor Author

pygarap commented Nov 18, 2025

@rushter I changed it for the private method, please recheck the PR, thanks 🙏

@rushter rushter merged commit 51ebd42 into rushter:master Nov 19, 2025
7 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants